package models


type SystemQuestionImage struct {
	Id           int `json:"id" xorm:"not null pk autoincr comment('主键') INT(11)"`
	QuestionId int `json:"question_id" xorm:"not null comment('题目主键') INT(11)"`
	ImgId string `json:"img_id" xorm:"not null comment('图片的MD')  INT(11)"`
}
var systemquestionimage ="system_question_image"

func(q *SystemQuestionImage) GetRow() bool {
	has, err := mEngine.Get(q)
	if err==nil &&  has  {
		return true
	}
	return false
}

//通过questionId,查询对应的imgIds
func(q *SystemQuestionImage) GetRowByImgId( ) bool{

	total, err:=mEngine.Table(systemquestionimage).Cols("img_id").
		Where("img_id =?  " ,q.ImgId).Count(q)

	if (err!=nil) || (total==0){
		return false
	}

	return true


}

//通过questionId,查询对应的imgIds
func(q *SystemQuestionImage) GetByQuestionId(questionId int ) ([]string,error){
	var imgIds []string
	err:=mEngine.Table(systemquestionimage).Cols("img_id").
		Where("question_id =?  " ,questionId).Find(&imgIds)


	return imgIds, err


}

func(q *SystemQuestionImage) DeleteByQuestionId(questionId int ) error{
	//No commitment
	_,err:=mEngine.Table(systemquestionimage).Where("question_id =?  " ,questionId).Delete(q)

	return  err

}

